package group2assignone.view;

import group2assignone.func.UCCtoALAdapter;
import group2assignone.model.Flight;
import group2assignone.ucm.customer.UCCancelGuest;
import java.awt.GridLayout;
import java.util.ArrayList;
import javax.swing.*;
import javax.swing.border.EtchedBorder;

/**
 * View used to list all of the flights in the database
 * @author group2
 */
public class ListFlightsView extends OurView {

    private JButton ok = new JButton("OK");
    private ArrayList<Flight> aFlights;
    private int size;

    /**
     * initialises the array of flights
     * @param flights
     */
    public ListFlightsView(ArrayList<Flight> flights) {
        aFlights = flights;
    }

    /**
     * Function to add the GUI components to the frame.
     */
    @Override
    public void addComponents() {

        setTitle("All Flights");

        size = aFlights.size();
        centerPanel.setLayout(new GridLayout(size + 1, 5, 10, 5));
        centerPanel.add(new JLabel("Flight Number"));
        centerPanel.add(new JLabel("Departs From"));
        centerPanel.add(new JLabel("Arrives At"));
        centerPanel.add(new JLabel("Date"));
        centerPanel.add(new JLabel("Departure Time"));
        centerPanel.add(new JLabel("Price"));
        centerPanel.add(new JLabel("Seating Capacity"));
        centerPanel.add(new JLabel("Remaining Seats"));
        centerPanel.add(new JLabel("Promotion"));
        for (int i = 0; i < size; i++) {
            centerPanel.add(new JLabel(aFlights.get(i).getFlightNum()));
            centerPanel.add(new JLabel(aFlights.get(i).getDepLoc()));
            centerPanel.add(new JLabel(aFlights.get(i).getArrLoc()));
            centerPanel.add(new JLabel(aFlights.get(i).getDate()));
            centerPanel.add(new JLabel(aFlights.get(i).getDepTime()));
            centerPanel.add(new JLabel(aFlights.get(i).getCost()));
            centerPanel.add(new JLabel(Integer.toString(aFlights.get(i).getSeatCap())));
            centerPanel.add(new JLabel(Integer.toString(aFlights.get(i).getRemSeats())));
            centerPanel.add(new JLabel(Integer.toString(aFlights.get(i).getPromotion())));
        }
        southPanel.add(ok);
        southPanel.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));

        ok.addActionListener(new UCCtoALAdapter(new UCCancelGuest(this)));
    }
}
